struct ko;
struct proc;
enum ko_type;
enum ko_mode;
/* !!! IMPORTANT: 开中断前绝对不能使用自旋锁 */

/* general */
void panic (char * msg); // done
int printk(const char *format, ...); // done

/* kernel memory allocator */
void kmeminit (); // done
void * kalloc (); // done
int kfree (void * pg); // done

/* virtual memory mapper */
void kvminit (); // done
int kvmmap (char * mapaddr, char * kpgaddr, char * pgtb, int flg, struct proc *p); // done

/* virtual memory read/write */
int vmread (char * pgtb, unsigned int from, char * to, unsigned int sz);  // done
int vmwrite (char * pgtb, char * from , unsigned int to, unsigned int sz); // done

/* kernel thread control */
void portal (void * currctx, void * nextctx); // done
void sched (); // !!! IMPORTANT: MUST ENABLE INTERRUPT // done
void yield (); // proc: I'm finished // done
struct proc * myproc (); // done
void sleep (void * wh); // done
void wakeup (void * wh); // done
// void userret(int tf, int upgtb); // call trampoline::userret
void seeyou (void* trapframe, void* pgtb); // jmp to userspace

/* syscall kernel handler */
/* process */
int fork (); // done
int riskfork (); //done
int exec (char * name, char* args); //todo
void exit (); //done
int wait (); //done
/* filesystem */
int pipe (int fds); //done
int dup (int ufd); // return ufd
int close (int ufd); // close ufd, !!! IMPORTANT:如果是空指针,不做操作
int open (char * name); //done
int read (int ufd, char * udest, int rdsz); //done
int write (int ufd, char * udest, int wrsz); //done
int ls (char * udest); //done
int rm (char * name); //done 

/* process copy */
int copyfdtab (struct proc * from, struct proc * to); // done
int copymem (struct proc * from, struct proc * to); // done
int copyctx (struct proc * from, struct proc * to); // done
int copytrapframe (struct proc * from, struct proc * to); // done

/* intrrupt on/of */
void intr_on (); // done
void intr_off (); // done

/* process allocator */
struct proc* allocproc (); // done
int freeproc (struct proc *); // done

/* kernel file object control */
//struct ko * ufd2ko (int ufd); // convert user fd to kernel file object pointer
int creat_pipeko (struct ko * o); // done
int creat_consko (struct ko * o); // done
int creat_fileko (char * path , struct ko * o); // done
struct ko * allocko (); // done
int initko (struct ko* o, int(*read)(struct ko*,void*,unsigned int), 
int(*write)(struct ko*,void*,unsigned int), int(*frinsd)(void*),void * ctx, char * name,
enum ko_mode mode ,enum ko_type type); // done
int freeko (struct ko * o); // done

/* elfloader */
unsigned int loadelf (char * name, void * pgtb); // done

/* init */
void pipeinit ();  // done
void koallocinit (); // done
void procinit (); // done
void mfsinit (); // done
void initneo (); // init the first process and jump to userspace 
void trapinit (); // done
void consinit (); // done
void lockinit (); // done
void elfloaderinit (); // done

/* traphdlr */
void cons_intrhdlr (); // done
void timer_intrhdlr (); // done
void mfs_intrhdlr (); // done
void psudo_intrhdlr (char *msg); // done
void missing_x_hdlr (); // done
void illinst_hdlr (); // done